import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_bloc_todo/model/todo_model.dart';
import 'package:flutter_bloc_todo/model/todo_model.g.dart';
import 'package:flutter_bloc_todo/view/todo/bloc/todo_cubit.dart';
import 'package:hive/hive.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:flutter_bloc_todo/repository/todo_repository.dart';

import 'view/todo/ToDoPage.dart';

Future<void> main() async {
  await Hive.initFlutter();
  Hive.registerAdapter(ToDoModelAdapter());
  await Hive.openBox<ToDoModel>(ToDoRepository.todoBox);
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MultiBlocProvider(
        providers: [
          BlocProvider<TodoCubit>(
            create: (BuildContext context) => TodoCubit(ToDoRepository()),
          )
        ],
        child: MaterialApp(
          theme: ThemeData(
              primarySwatch: Colors.pink,
              visualDensity: VisualDensity.adaptivePlatformDensity),
          home: TodoPage(),
        ));
  }
}
